package springboottest.springboot;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import springboottest.springboot.entity.UserEntity;
import springboottest.springboot.service.SpringBootService;

@RestController
@RequestMapping("test")
public class SpringBootTest {

	@GetMapping("/hello")
	@MyLogTest(desc = "indexHello")
	public String index() {
		return "hello world";

	}

	@GetMapping("/hello/{a}")
	@MyLogTest(desc = "indexHello-a")
	public String index(@PathVariable String a) {
		return a;

	}

	@Autowired
	SpringBootService springBootService;

	@GetMapping("/hello/{arg}/{a}")
	@MyLogTest(desc = "indexHello")
	public String index(@PathVariable String arg, @PathVariable String a) {
		String result = springBootService.hello(arg);
		return result + "---" + a;

	}

	@GetMapping("/errorHandler")
	public String error() {

		throw new MyRuntimeException("110", "异常报警");

	}

	@GetMapping("/user/{userId}")
	@MyLogTest(desc = "indexHello")
	public UserEntity user(@PathVariable Long userId) {

		return springBootService.findUserEntityByUserId(userId);

	}

}
